﻿/**
Move a MovieClip to a specified x and y over time
<code>
	var s:Slide = new Slide(instanceName,1);
	s.moveClipTo(250,500,3);
</code>
*/

class com.vitaly.Slide {	

private var target:MovieClip;
private var depth:Number;

/**
@param target the MovieClip you want to move
@param depth the depth of the MovieClip
*/

function Slide($target:MovieClip,$depth:Number) {

	target = $target;
	depth = $depth;

}

/**
@param x the x position to move to
@param y the y position to move to
@param the speed of the movement - higher numbers are slower
*/

public function moveClipTo (x:Number,y:Number,s:Number){

	target.createEmptyMovieClip("container",depth);
	
	target.container.targetX = x;
	target.container.targetY = y;
	target.container.startSpeed = s;
	target.container.precision = 1;
	target.container.onEnterFrame = function(){
		
		if(Math.abs(this._parent._x - this.targetX) < this.precision && Math.abs(this._parent._y - this.targetY) < this.precision){
			this._parent._x = this.targetX;
			this._parent._y = this.targetY;
			this.removeMovieClip();
			}
		this._parent._x -= (this._parent._x - this.targetX)/this.startSpeed;
		this._parent._y -= (this._parent._y - this.targetY)/this.startSpeed;
		}


	
	}
	



}


